/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.presentationlayer;

import mnstudent.global.MyTableCellRender;
import mnstudent.global.DataTable;
import mnstudent.global.Standard;
import mnstudent.businessLayer.*;
import mnstudent.datatranferobject.*;
import java.awt.event.*;
import java.text.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author lee
 */
public class frmCoursesRegistration extends javax.swing.JPanel {

    private RegistrationCoursesBLL m_RegistrationCoursesBLL;
    private SemesterBLL m_SemesterBLL;
    private StudentBLL m_StudentBLL;
    private InfoSemesterYearBLL m_InfoSemesterYearBLL;
    private AcademicYearBLL m_AcademicYearBLL;
    private SubjectBLL m_SubjectBLL;
    private RegulationBLL m_RegulationBLL;
    
    private SemesterDTO objAddNewSemester;
    private AcademicYearDTO objAddNewYear;
    private StudentDisplayDTO objStudent;
    
    private ArrayList<SemesterDTO> listSemesterObj;
    private ArrayList<AcademicYearDTO> listYearObj;
    private ArrayList<SubjectDisplay> arrSubjectRegistration, arrSubjectRegistrationActionUpdate;
    
    private DefaultTableModel m_Model, m_ModelSubjectRegistration;
    private final SimpleDateFormat formatDate= new SimpleDateFormat("dd/MM/yyyy");
    private final NumberFormat formatMoney = new DecimalFormat("#,###,###");
    private boolean isCanAction = false;
    private static float scorePassed;
    
    private int theory = 0;
    private int pratice = 0;
    private int totalFee = 0;
    private int amountIsReduces = 0;
    private String strTheory = "Lý thuyết", strPratice = "Thực hành";
    private int moneyTheory;
    private int moneyPratice;
    private String idRegistration;
    /**
     * Creates new form frmFaculty
     */
    public frmCoursesRegistration() {
        initComponents();
        initControls();
        init();
        //prepare();
    }

    private void initControls()
    {
        jxTxtStudentId.setEditable(true);
        jxTxtStudentId.requestFocus();
        
        jxTxtNameOfMajor.setEditable(false);
        jxTxtNameOfStudent.setEditable(false);
        
        jxDpDateRegistration.setEditable(false);
        jxTbListSubjectRegistration.setEditable(false);
        jxTbListSubjectWillOpen.setEditable(false);
        
        jxCbSemester.setEnabled(false);
        jxCbYear.setEnabled(false);
        
        jxBtnAddTo.setEnabled(false);
        jxBtnRemove.setEnabled(false);
        jxBtnOtherStudent.setEnabled(false);
        jxBtnSave.setEnabled(false);
        jxBtnCancel.setEnabled(false);
        jxBtnUpdate.setEnabled(false);
        jxBtnShowRegistration.setEnabled(false);
    }
    
    private void refreshData(){
        
        objStudent = null;
        jxTxtStudentId.setText("");
        jxTxtStudentId.setEditable(true);
        jxTxtStudentId.requestFocus();
        jxTxtNameOfStudent.setText("");
        jxTxtNameOfMajor.setText("");
        
        jxLblCountCreditPractice.setText("null");
        jxLblCountCreditTheory.setText("null");
        jxLblTotalCredit.setText("null");
        jxLblTotalMoneyFee.setText("null");
        
        jxBtnSave.setEnabled(false);
        jxBtnCancel.setEnabled(false);
        jxBtnAddTo.setEnabled(false);
        jxBtnRemove.setEnabled(false);
        jxBtnOtherStudent.setEnabled(false);

        //Set ngay dk
        jxDpDateRegistration.setDate(null);
        jxCbSemester.setSelectedItem(null);
        jxCbYear.setSelectedItem(null);
    }
    
    private void refreshDataControls()
    {
        refreshData();
        //neu co dl trong nag thi reset toan bo
        m_Model.fireTableDataChanged();
        m_Model.fireTableStructureChanged();
        m_Model.getDataVector().removeAllElements();
        DataTable.addRow(m_RegistrationCoursesBLL.getAllSubjectDisplayOpenBySemesterIDYearIDMajorID( "", "", ""), m_Model);
        arrSubjectRegistration.clear();
        initJXTableSubjectRegistration(arrSubjectRegistration);
    }
    private void init()
    {
        // Thiet lap gioi han ky tu cho mssv
        jxTxtStudentId.addKeyListener(new KeyAdapter() {
                public void keyTyped(KeyEvent e){
                    char vChar = e.getKeyChar();
                    int len = jxTxtStudentId.getText().length();
                    if (!(Character.isDigit(vChar)
                            || (vChar == KeyEvent.VK_BACK_SPACE)
                            || (vChar == KeyEvent.VK_DELETE)
                            || (vChar == KeyEvent.VK_ENTER)
                            || (vChar == KeyEvent.VK_TAB))||(len > Standard.MAX_LEN_PHONE)) {
                            e.consume();
                    }
                }
        });
          //Set lai text cac button cua dialog
        UIManager.put("OptionPane.cancelButtonText", "Hủy");
        UIManager.put("OptionPane.noButtonText", "Không");
        UIManager.put("OptionPane.okButtonText", "Vâng");
        UIManager.put("OptionPane.yesButtonText", "Có");
        //
        this.m_RegistrationCoursesBLL = new RegistrationCoursesBLL();
        this.m_StudentBLL = new StudentBLL();
        this.m_SemesterBLL = new SemesterBLL();
        this.m_AcademicYearBLL = new AcademicYearBLL();
        this.m_InfoSemesterYearBLL = new InfoSemesterYearBLL();
        this.m_RegulationBLL = new RegulationBLL();
        this.m_SubjectBLL = new SubjectBLL();
        scorePassed = Float.valueOf(m_RegulationBLL.getRegulationByLabelToObject("DiemDat").getValue());
        bindingDataToComboBox();
        
        moneyTheory = m_RegistrationCoursesBLL.getMoneyOfCreditByNameKindOfSubject(strTheory);
        moneyPratice = m_RegistrationCoursesBLL.getMoneyOfCreditByNameKindOfSubject(strPratice);
    }
    
    private void initObjectStudentRegistration(String _idStudent)
    {
        _idStudent.replaceAll("\\s+", "");
        objStudent = m_StudentBLL.getInfoStudentById(_idStudent);
        if(objStudent == null)
        {
            JOptionPane.showMessageDialog(null, "Mã số sinh viên không tồn tại. \nVui lòng kiểm tra lại hoặc thêm mới sinh viên!");
            jxTxtStudentId.setText("");
        }
        else
        {
            if(objStudent.getNameOfStateID().toLowerCase().equals("đang học")){//duoc phep dk
               
                jxBtnOtherStudent.setEnabled(true);
                jxTxtNameOfStudent.setText(objStudent.getFullName());
                jxTxtNameOfMajor.setText(objStudent.getNameOfMajor());
                jxTxtStudentId.setEditable(false);
                //Set ngay dk
                jxDpDateRegistration.setDate(Standard.getDateSystem());
                //Set nam hoc, lay len nam lon nhat duoi database kiem tra 
                //neu bang nam hien tai thi cho dk va gan gia tri cho ComboBox nam hoc
                //nguoc lai thi yeu cau them nam hoc va thong tin nam hoc do
                String maxYearInDatabase = m_AcademicYearBLL.getMaxAcademicYear();
                if(compareAcademicYearWithCurrentYear(maxYearInDatabase)){//dung
                    for(AcademicYearDTO obj : listYearObj)
                    {
                        if(obj.getNameOfAcademicYear().equals(maxYearInDatabase))
                            jxCbYear.setSelectedItem(obj);
                    }
                    //thiet lap hoc ky
                    SemesterDTO currentSemester = null;
                    ArrayList<InfoSemesterYearDTO> arrInfoSemesterYear = m_InfoSemesterYearBLL.
                            getInfoSemesterYearByIdYear(((AcademicYearDTO)jxCbYear.
                            getSelectedItem()).
                            getAcademicYearID());
                    if(arrInfoSemesterYear.size()>0)
                    {
                        Date currentDate = Standard.getDateSystem();
                        for(InfoSemesterYearDTO obj : arrInfoSemesterYear)
                        {
                            if(currentDate.after(obj.getDateStartCourseRegistration()) && currentDate.before(obj.getDealineCourseRegistration()))
                            {
                                currentSemester = new SemesterDTO();
                                currentSemester.setSemesterID(obj.getSemesterID());
                                break;
                            }
                        }
                    }
                    //chon ra hoc ky
                    if(currentSemester != null){
                        for(SemesterDTO obj : listSemesterObj)
                        {
                            if(currentSemester.getSemesterID().equals(obj.getSemesterID()))
                                jxCbSemester.setSelectedItem(obj);
                        }
                        isCanAction = true;
                        initJxTableSubjectWillOpen(currentSemester.getSemesterID(), ((AcademicYearDTO)jxCbYear.getSelectedItem()).getAcademicYearID(), objStudent.getMajorID());
                        
                        //Kiem tra neu sinh vien da có đang ký rùi thì chỉ cho chỉnh sửa khi còn hạn đk
                        idRegistration = m_RegistrationCoursesBLL.getIdOfRegistrationCoursesByStudentIdAndSemesterIDYearId(objStudent.getStudentID(), 
                                                                    currentSemester.getSemesterID(), 
                                                                    ((AcademicYearDTO)jxCbYear.getSelectedItem()).getAcademicYearID());
                        if(idRegistration == null){
                            jxTbListSubjectRegistration.m_isAdd = true;
                            jxTbListSubjectRegistration.m_isUpdate = false;
                            jxBtnAddTo.setEnabled(true);
                            jxBtnSave.setEnabled(true);
                            jxBtnCancel.setEnabled(true);
                            jxBtnUpdate.setEnabled(false);
                            jxBtnShowRegistration.setEnabled(false);
                        }
                        else{//sinh vien co dk rui
                            jxBtnUpdate.setEnabled(true);
                            jxBtnSave.setEnabled(false);
                            jxBtnCancel.setEnabled(false);
                            jxBtnShowRegistration.setEnabled(true);
                            jxTbListSubjectRegistration.m_isAdd = false;

                            
                            //Load dl dua len bang cac mon da dk
                            arrSubjectRegistration = m_RegistrationCoursesBLL.getListSubjectDisplayRegistrationCoursesBySutdentId(objStudent.getStudentID(), 
                                                                    currentSemester.getSemesterID(), 
                                                                    ((AcademicYearDTO)jxCbYear.getSelectedItem()).getAcademicYearID());
                            initJXTableSubjectRegistration(arrSubjectRegistration);
                            //Tinh toan so tien
                            calculatorInfoRegistration();
                        }
                    }
                    else
                    {
                        isCanAction = false;
                        JOptionPane.showMessageDialog(null, "Chưa đến ngày đăng ký môn học. \n Vui lòng chờ!");
                        refreshData();
                    }       
                }else{
                    isCanAction = false;
                    JOptionPane.showMessageDialog(null, "Năm học mới chưa được tạo.\n Vui lòng thêm mới năm học!");
                    refreshData();
                }
                
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Sinh viên này hiện ở trạng thái " + 
                        objStudent.getNameOfStateID().toLowerCase() +" nên không được đăng ký môn học");
            }
        }
    }
    
    private void initJxTableSubjectWillOpen(String _idSemester, String _idYear, String _idMajor){    
        //JXTable Cac mon hoc se mo cua nganh trong hoc ky - nam hoc
        //Tien hanh dua danh sach mon hoc mo cua nganh sinh vien trong hoc ky - nam hoc hien tai
        m_Model = (DefaultTableModel)jxTbListSubjectWillOpen.getModel();
        m_Model.fireTableDataChanged();
        m_Model.fireTableStructureChanged();
        DataTable.addRow(m_RegistrationCoursesBLL.getAllSubjectDisplayOpenBySemesterIDYearIDMajorID(_idSemester,_idYear, _idMajor), m_Model);
        //get selected item
        jxTbListSubjectWillOpen.setDefaultRenderer(Object.class, new MyTableCellRender());
        jxTbListSubjectWillOpen.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {

                if(!(jxTbListSubjectWillOpen.getSelectionModel().isSelectionEmpty()))
                {
                    //retrieving the selected row index
                    //if a single row is selected from the table, take each cell values into the controls
                    if (jxTbListSubjectWillOpen.getRowSelectionAllowed()&&jxTbListSubjectWillOpen.getRowCount()>0) {
                        if(jxTbListSubjectRegistration.m_isAdd||jxTbListSubjectRegistration.m_isUpdate)
                        {
                            jxTxtStudentId.requestFocus();
//                            int rs = JOptionPane.showOptionDialog(null,
//                                        "Vui lòng lưu thay đổi trước khi chuyển sang dòng khác!",
//                                        "Cảnh báo",
//                                        JOptionPane.YES_NO_OPTION,
//                                        JOptionPane.QUESTION_MESSAGE,
//                                        null,
//                                        null,
//                                        null);
//                            if(rs == 0 )//Yes
//                            {
//                                save();
//                            }
//                            else
//                            {
//                                cancelAction();
//                            }
                        }
                        else
                        {
                            //bindingDataToControls();
                        }
                    }
                }
            }
          });
        //khoi tao list cac mon dc chon dk
        arrSubjectRegistration = new ArrayList<>();
    }
    //JXTable Cac mon hoc dc dk
    private void initJXTableSubjectRegistration(ArrayList<SubjectDisplay> _arrSubjectRegistration)
    {
        m_ModelSubjectRegistration = (DefaultTableModel)jxTbListSubjectRegistration.getModel();
        m_ModelSubjectRegistration.fireTableDataChanged();
        m_ModelSubjectRegistration.fireTableStructureChanged();
        if(_arrSubjectRegistration.size()>0){
            m_ModelSubjectRegistration.getDataVector().removeAllElements();
        
            for(SubjectDisplay obj : _arrSubjectRegistration)
            {
                Vector _row = new Vector(); 
                _row.addElement(obj.getSubjectID());
                _row.addElement(obj.getNameOfSubject());
                _row.addElement(obj.getNameKindOfSubject());
                _row.addElement(obj.getCoutSCredit());
                m_ModelSubjectRegistration.addRow(_row);     
            }
        }
        else
        {
            if(m_ModelSubjectRegistration.getRowCount()>0)
            {
                for(int i = m_ModelSubjectRegistration.getRowCount() - 1; i>=0; i--)
                    m_ModelSubjectRegistration.removeRow(i);
            }
        }
        jxTbListSubjectRegistration.setDefaultRenderer(Object.class, new MyTableCellRender());
      
    } 
    
    private void bindingDataToComboBox()
    {
         //ComboxBox Hoc ky
        listSemesterObj = m_SemesterBLL.getAllSemesterToArray();
        objAddNewSemester = new SemesterDTO("HKThemMoi", "Thêm mới...");
        listSemesterObj.add(objAddNewSemester);
        DefaultComboBoxModel dfCbModelS = new DefaultComboBoxModel(listSemesterObj.toArray());
        jxCbSemester.setModel(dfCbModelS);
        jxCbSemester.setSelectedItem(null);
        
        //ComboxBox Nam Hoc
         listYearObj = m_AcademicYearBLL.getAllAcademicYearToArray();
        objAddNewYear = new AcademicYearDTO("NHThemMoi", "Thêm mới...");
        listYearObj.add(objAddNewYear);
        DefaultComboBoxModel dfCbModel = new DefaultComboBoxModel(listYearObj.toArray());
        jxCbYear.setModel(dfCbModel);
        jxCbYear.setSelectedItem(null);
    }
    
    private void bindingDataToControls()
    {
      
    }

    /**
     * Ham xoa 1 khoa dc chon
     * @param rowSelected
     * @return 
     */
    private boolean isDelete(int rowSelected)
    {
        boolean m_isDelete = false;

        String id = this.jxTbListSubjectRegistration.getValueAt(rowSelected, 0).toString();

       

        return m_isDelete;
    }
     /**
      * Ham xoa 1 luc nhieu khoa
      * @return 
      */
    private boolean isDeleteMoreInfoSemesterYear()
    {
        boolean m_isDelete = true;
        int[] arrRowSelected = this.jxTbListSubjectRegistration.getSelectedRows();
        for(int i = arrRowSelected.length - 1; i >=0; i--)
        {
            if(!isDelete(arrRowSelected[i])){
                JOptionPane.showMessageDialog(null, 
                        "Xóa thất bại khoa: "+ jxTbListSubjectRegistration.getValueAt(arrRowSelected[i], 1) , 
                        "Lỗi", 
                        JOptionPane.YES_OPTION);
                m_isDelete = false;
            }
        }
        return m_isDelete;
    }
    /**
     * Ham thuc hien insert Khoa xuong database
     * @return 
     */
    private void saveToDatabase()
    {
        if(checkData())
        {
            java.sql.Date dateRegitration = new java.sql.Date(jxDpDateRegistration.getDate().getYear(), 
                     jxDpDateRegistration.getDate().getMonth(),
                     jxDpDateRegistration.getDate().getDate());
            SemesterDTO objSemester = (SemesterDTO)jxCbSemester.getSelectedItem();
            AcademicYearDTO objYear = (AcademicYearDTO)jxCbYear.getSelectedItem();
            
            RegistrationCoursesDTO objRegistration = new RegistrationCoursesDTO("DK0000***",
                    objStudent.getStudentID(),
                    dateRegitration,
                    theory,
                    pratice,
                    LoginDTO.getID(),
                    objSemester.getSemesterID(),
                    objYear.getAcademicYearID(),
                    totalFee,
                    totalFee,
                    amountIsReduces,
                    arrSubjectRegistration
                    );
            //Luu xuong
            if(m_RegistrationCoursesBLL.insertRegistrationCoursesToDatabase(objRegistration))
            {
                objRegistration.setRegistrationCoursesID(m_RegistrationCoursesBLL.getIDegistrationCoursesToString());
                //Luu thong tin vao bang CT_PHIEUDANGKY
                if(saveListDetailedRegistrationCourses(objRegistration))
                {
                    JOptionPane.showOptionDialog(null, 
                        "Lưu xuống thành công!", 
                        "Thông báo", 
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                        //neu Cập nhật thanh cong
                       this.jxTbListSubjectRegistration.m_isAdd = false;
                       initControls();
                       jxBtnShowRegistration.setEnabled(true);
                       jxBtnUpdate.setEnabled(true);
                       jxBtnOtherStudent.setEnabled(true);
                       //refreshDataControls();
                    }
                    else
                    {
                         JOptionPane.showMessageDialog(null,"Lưu xuống thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
                    } 
            }
            
        }
    }

    private boolean saveListDetailedRegistrationCourses(RegistrationCoursesDTO _objRegistration)
    {
        ArrayList<DetailedRegistrationCoursesDTO> temp = new ArrayList<>();
        for(SubjectDisplay obj : _objRegistration.getListSubjectRegistration())
        {
            DetailedRegistrationCoursesDTO objDetailed = new DetailedRegistrationCoursesDTO(_objRegistration.getRegistrationCoursesID(),
                                                                                obj.getSubjectID());
            if(objDetailed != null)
                temp.add(objDetailed);
        }
        
        //Luu
        if(m_RegistrationCoursesBLL.insertListSubjectRegistrationToDetailedRegistration(temp))
            return true;
        return false;
    }
    /**
     * Ham thuc hien cap nhat Khoa
     * @return 
     */
    private void updateToDatabase()
    {
        if(checkData())
        {
            java.sql.Date dateRegitration = new java.sql.Date(jxDpDateRegistration.getDate().getYear(), 
                     jxDpDateRegistration.getDate().getMonth(),
                     jxDpDateRegistration.getDate().getDate());
            SemesterDTO objSemester = (SemesterDTO)jxCbSemester.getSelectedItem();
            AcademicYearDTO objYear = (AcademicYearDTO)jxCbYear.getSelectedItem();
            
            RegistrationCoursesDTO objRegistration = new RegistrationCoursesDTO(idRegistration,
                    objStudent.getStudentID(),
                    dateRegitration,
                    theory,
                    pratice,
                    LoginDTO.getID(),
                    objSemester.getSemesterID(),
                    objYear.getAcademicYearID(),
                    totalFee,
                    totalFee,
                    amountIsReduces,
                    arrSubjectRegistration
                    );
            //Luu xuong
            if(m_RegistrationCoursesBLL.updateRegistrationCoursesByIdToDatabase(objRegistration))
            {
                //Xoa het cac mon hoc theo ma phieu dk trong bang CT_PHIEUDK
                if(deleteAllDetailedRegistrationByRegistrationCoursesID(objRegistration)){
                //Luu thong tin vao bang CT_PHIEUDANGKY
                    if(saveListDetailedRegistrationCourses(objRegistration))
                    {
                        JOptionPane.showOptionDialog(null, 
                            "Cập thành công!", 
                            "Thông báo", 
                            JOptionPane.YES_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            null,
                            null,
                            null);
                            //neu Cập nhật thanh cong
                           this.jxTbListSubjectRegistration.m_isAdd = false;
                           initControls();
                           jxBtnUpdate.setEnabled(true);
                           jxBtnOtherStudent.setEnabled(true);
                           jxBtnShowRegistration.setEnabled(true);
                           arrSubjectRegistration = m_RegistrationCoursesBLL.getListSubjectDisplayRegistrationCoursesBySutdentId(objStudent.getStudentID(), 
                                                                    objRegistration.getSemesterID(), 
                                                                    objRegistration.getAcademicYearID());
                           //initJXTableSubjectRegistration(arrSubjectRegistration);
                            //Tinh toan so tien
                           //calculatorInfoRegistration();
                    }
                    else
                    {
                         JOptionPane.showMessageDialog(null,"Lưu xuống thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
                    } 
                }
            }
            
        }
    }
    
    private boolean deleteAllDetailedRegistrationByRegistrationCoursesID(RegistrationCoursesDTO _objRegistration)
    {
         //Luu
        if(m_RegistrationCoursesBLL.deleteListDetailedRegistrationToDatabase(_objRegistration.getRegistrationCoursesID()))
            return true;
        return false;
    }
     /**
     * Ham thuc hien viec cap nhat va update
     */
     private void save()
    {
         if(this.jxTbListSubjectRegistration.m_isAdd)
        {
            saveToDatabase();
        }
        else
            if(this.jxTbListSubjectRegistration.m_isUpdate)
            {
                updateToDatabase();
            }
    }
    
    private void cancelAction()
     {

     
     }
   
    private boolean compareAcademicYearWithCurrentYear(String _input)
    {
        //còn năm học mà nhỏ hơn năm hiện tại thì chi cho xem thui    
        int rs = 0;
        int currentYear = Standard.getDateSystem().getYear() + 1900;
        int[] temp = Standard.cutStringGetArrayInt(_input);
        for(int i = 0; i<temp.length; i++)
            if(temp[i] == currentYear)
                return true;
      
        return false;
    }
    
    private void calculatorInfoRegistration()
    {
        if(arrSubjectRegistration.size()>0)
        {
            theory = 0;
            pratice = 0;
            totalFee = 0;
            amountIsReduces = 0;
            int totalCredit = 0;

            for(int i = 0; i< arrSubjectRegistration.size(); i++)
            {
                if(arrSubjectRegistration.get(i).getNameKindOfSubject().toLowerCase().equals(strPratice.toLowerCase()))//thuc hanh
                {
                    pratice += arrSubjectRegistration.get(i).getCoutSCredit();                 
                }
                else
                {
                    //if(arrSubjectRegistration.get(i).getNameKindOfSubject().toLowerCase().equals(strTheory.toLowerCase()))
                        theory += arrSubjectRegistration.get(i).getCoutSCredit();
                }
            }
            
            totalCredit = pratice + theory;
            //Tinh tien hoc phi phai dong theo doi tuong cua sinh vien
            totalFee = moneyPratice*pratice + moneyTheory*theory;
            amountIsReduces = (totalFee * getMaxRateOfStudentObject())/100;//so tien dc giam
            totalFee = totalFee - amountIsReduces;//tong tien phai dong
            
            jxLblCountCreditPractice.setText(String.valueOf(pratice));
            jxLblCountCreditTheory.setText(String.valueOf(theory));
            jxLblTotalCredit.setText(String.valueOf(totalCredit));
            jxLblTotalMoneyFee.setText(formatMoney.format(totalFee) + " vnđ");
        }else{
            jxLblCountCreditPractice.setText("0");
            jxLblCountCreditTheory.setText("0");
            jxLblTotalCredit.setText("0");
            jxLblTotalMoneyFee.setText("0 vnđ");
        }
            
    }
    //Ham lay doi tuong sinh vien co % giam hoc phi cao nhat
    private int getMaxRateOfStudentObject()
    {
        if(objStudent.getListPriorityObject().size() == 1)
            return objStudent.getListPriorityObject().get(0).getRate();
        else{
            int max = objStudent.getListPriorityObject().get(0).getRate();
            for(PriorityObjectDTO objPri : objStudent.getListPriorityObject())
            {
                if(max < objPri.getRate())
                    max = objPri.getRate();
            }
            return max;
        }
    }
    /**
     * Phương thức kiểm tra xem môn học đk có hợp lệ hay ko(môm tiên quyết + môn lt-th)
     * @return 
     */
    private boolean checkSubjectRegistrantionIsValid()
    {
        return false;
    }
    /**
     * Phương thức kiểm tra môn học tiên quyết có trên 5 ko nếu môn đó có môn tiên quyết
     * @return 
     */
    private boolean checkSubjectPrerequisiteIsValid(SubjectDisplay objectSub)
    {
        ArrayList<SubjectDTO> listSubjectPrerequisite = m_SubjectBLL.getAllPrerequisiteSubjectOfSubjectByIdFromDatabaseToArray(objectSub.getSubjectID());
        if(listSubjectPrerequisite.size() == 0)//khong co mon tien quyet
            return true;
        else{
            //Bat dau kiem tra xem mon do hoc chua va diem so cua no
            for(SubjectDTO obj : listSubjectPrerequisite)
            {
                //kiem tra mon do hoc chua?
                float scores = m_RegistrationCoursesBLL.getAfterScoresSubjectOfStudentByStudentId(objStudent.getStudentID(), obj.getSubjectID());
                if(scores == -1)//Sinhvien chua hoc mon nay--> chua co diem--> ko cho dk lun
                {
                    JOptionPane.showMessageDialog(null, "Sinh viên này chưa học môn tiên quyết của môn '" + objectSub.getNameOfSubject() +"'.");
                    return false;
                }//nguoc lai co diem
                else{
                    if(scores >= scorePassed)//neu diem mon tien quyet thoa dk thi cho dk
                    {
                        return true;
                    }
                    else{
                        JOptionPane.showMessageDialog(null, "Môn học '"+ objectSub.getNameOfSubject() +"' có điểm môn tiên quyết không đạt.");
                        return false;
                    }
                }
            }
        }
        return false;
    }
    /**
     * Phương thức kiểm tra xem có đk môn có môn thực hành hay ko, nếu đk môn lý thuyết phải dk môn th
     * ý tưởng: neu dk mon hoc ly thuyet thi tu dong dk mon th luon
     * @return 
     */
    private boolean checkSubjectTheoryAndPratice()
    {
        return false;
    }
    
    /**
     * Phuong thuc kiem tra du lieu truoc khi luu xuong database
     * @return 
     */
    private boolean checkData()
    {
        if(jxTxtStudentId.getText().equals("")||
                jxTxtNameOfMajor.getText().equals("")||
                jxTxtNameOfStudent.getText().equals("")||
                jxCbSemester.getSelectedIndex() == -1||
                jxCbYear.getSelectedIndex() == -1||
                jxDpDateRegistration.getDate() == null||
                arrSubjectRegistration.isEmpty()){
             JOptionPane.showMessageDialog(null, "Dữ liệu không được bỏ trống!");
             return false;
        }
        else
            return true;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jxpanDetails = new org.jdesktop.swingx.JXPanel();
        jpanTableDetails = new javax.swing.JPanel();
        jpanContent = new javax.swing.JPanel();
        jpanFuntionalDetails = new javax.swing.JPanel();
        jXPanel3 = new org.jdesktop.swingx.JXPanel();
        jXLabel10 = new org.jdesktop.swingx.JXLabel();
        jXLabel11 = new org.jdesktop.swingx.JXLabel();
        jXLabel12 = new org.jdesktop.swingx.JXLabel();
        jXLabel13 = new org.jdesktop.swingx.JXLabel();
        jxLblCountCreditTheory = new org.jdesktop.swingx.JXLabel();
        jxLblCountCreditPractice = new org.jdesktop.swingx.JXLabel();
        jxLblTotalCredit = new org.jdesktop.swingx.JXLabel();
        jxLblTotalMoneyFee = new org.jdesktop.swingx.JXLabel();
        jXPanel4 = new org.jdesktop.swingx.JXPanel();
        jxBtnCancel = new org.jdesktop.swingx.JXButton();
        jxBtnSave = new org.jdesktop.swingx.JXButton();
        jxBtnShowRegistration = new org.jdesktop.swingx.JXButton();
        jxBtnUpdate = new org.jdesktop.swingx.JXButton();
        jxpanCenter = new org.jdesktop.swingx.JXPanel();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jxTbListSubjectWillOpen = new mnstudent.global.MyTable();
        jxpanFindNavibar1 = new org.jdesktop.swingx.JXPanel();
        jxSearchFaculty2 = new org.jdesktop.swingx.JXSearchField();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jXLabel4 = new org.jdesktop.swingx.JXLabel();
        jXPanel5 = new org.jdesktop.swingx.JXPanel();
        jxBtnAddTo = new org.jdesktop.swingx.JXButton();
        jxBtnRemove = new org.jdesktop.swingx.JXButton();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jScrollPane = new javax.swing.JScrollPane();
        jxTbListSubjectRegistration = new mnstudent.global.MyTable();
        jxpanFindNavibar2 = new org.jdesktop.swingx.JXPanel();
        jxSearchFaculty4 = new org.jdesktop.swingx.JXSearchField();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        jXLabel7 = new org.jdesktop.swingx.JXLabel();
        jxpanHeader = new org.jdesktop.swingx.JXPanel();
        jxpanTitleHeader = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jxpanInfoHeader = new org.jdesktop.swingx.JXPanel();
        jxpanInfo = new org.jdesktop.swingx.JXPanel();
        jxLabNameOfFaculty = new org.jdesktop.swingx.JXLabel();
        jxCbSemester = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty2 = new org.jdesktop.swingx.JXLabel();
        jxCbYear = new org.jdesktop.swingx.JXComboBox();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jxTxtStudentId = new org.jdesktop.swingx.JXTextField();
        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jxTxtNameOfStudent = new org.jdesktop.swingx.JXTextField();
        jXLabel8 = new org.jdesktop.swingx.JXLabel();
        jxTxtNameOfMajor = new org.jdesktop.swingx.JXTextField();
        jXLabel9 = new org.jdesktop.swingx.JXLabel();
        jxDpDateRegistration = new org.jdesktop.swingx.JXDatePicker();
        jxBtnOtherStudent = new org.jdesktop.swingx.JXButton();

        setPreferredSize(new java.awt.Dimension(900, 569));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        setLayout(new java.awt.BorderLayout());

        jxpanDetails.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanDetails.setLayout(new java.awt.BorderLayout());

        jpanTableDetails.setLayout(new java.awt.BorderLayout());

        jpanContent.setLayout(new java.awt.BorderLayout());

        jpanFuntionalDetails.setLayout(new java.awt.BorderLayout());

        jXPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jXLabel10.setText("Tổng số tín  chỉ:");

        jXLabel11.setText("Tổng tiền học phí phải đóng:");

        jXLabel12.setText("Số tín  chỉ lý thuyết:");

        jXLabel13.setText("Số tín  chỉ thực hành:");

        jxLblCountCreditTheory.setForeground(new java.awt.Color(255, 0, 51));
        jxLblCountCreditTheory.setText("null");

        jxLblCountCreditPractice.setForeground(new java.awt.Color(255, 0, 51));
        jxLblCountCreditPractice.setText("null");

        jxLblTotalCredit.setForeground(new java.awt.Color(255, 0, 51));
        jxLblTotalCredit.setText("null");

        jxLblTotalMoneyFee.setForeground(new java.awt.Color(255, 0, 51));
        jxLblTotalMoneyFee.setText("null");

        javax.swing.GroupLayout jXPanel3Layout = new javax.swing.GroupLayout(jXPanel3);
        jXPanel3.setLayout(jXPanel3Layout);
        jXPanel3Layout.setHorizontalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxLblCountCreditTheory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(180, 180, 180)
                .addComponent(jXLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxLblCountCreditPractice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(230, 230, 230)
                .addComponent(jXLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxLblTotalCredit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(148, 148, 148)
                .addComponent(jXLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxLblTotalMoneyFee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(237, 237, 237))
        );
        jXPanel3Layout.setVerticalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLblCountCreditTheory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLblCountCreditPractice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLblTotalCredit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLblTotalMoneyFee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jpanFuntionalDetails.add(jXPanel3, java.awt.BorderLayout.PAGE_START);

        jxBtnCancel.setText("Hủy thao tác");
        jxBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnCancelActionPerformed(evt);
            }
        });

        jxBtnSave.setText("Lưu xuống");
        jxBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnSaveActionPerformed(evt);
            }
        });

        jxBtnShowRegistration.setText("Xem phiếu đăng ký");
        jxBtnShowRegistration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnShowRegistrationActionPerformed(evt);
            }
        });

        jxBtnUpdate.setText("Sửa đổi");
        jxBtnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnUpdateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel4Layout = new javax.swing.GroupLayout(jXPanel4);
        jXPanel4.setLayout(jXPanel4Layout);
        jXPanel4Layout.setHorizontalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel4Layout.createSequentialGroup()
                .addContainerGap(423, Short.MAX_VALUE)
                .addComponent(jxBtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jxBtnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jxBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jxBtnShowRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(424, Short.MAX_VALUE))
        );
        jXPanel4Layout.setVerticalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxBtnSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxBtnShowRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxBtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpanFuntionalDetails.add(jXPanel4, java.awt.BorderLayout.CENTER);

        jpanContent.add(jpanFuntionalDetails, java.awt.BorderLayout.PAGE_END);

        jxpanCenter.setLayout(new javax.swing.BoxLayout(jxpanCenter, javax.swing.BoxLayout.LINE_AXIS));

        jXPanel2.setLayout(new java.awt.BorderLayout(0, 1));

        jxTbListSubjectWillOpen.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã môn học", "Tên môn học", "Loại môn học", "Số tín chỉ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jxTbListSubjectWillOpen.setGridColor(new java.awt.Color(153, 153, 153));
        jxTbListSubjectWillOpen.setSelectionBackground(new java.awt.Color(204, 204, 204));
        jxTbListSubjectWillOpen.setSortsOnUpdates(false);
        jxTbListSubjectWillOpen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jxTbListSubjectWillOpenMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(jxTbListSubjectWillOpen);

        jXPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jxpanFindNavibar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar1.setPreferredSize(new java.awt.Dimension(914, 30));

        jXLabel3.setText("Tìm kiếm môn học:");

        jXLabel4.setText("Danh sách môn học mở trong");
        jXLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout jxpanFindNavibar1Layout = new javax.swing.GroupLayout(jxpanFindNavibar1);
        jxpanFindNavibar1.setLayout(jxpanFindNavibar1Layout);
        jxpanFindNavibar1Layout.setHorizontalGroup(
            jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jxSearchFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jxpanFindNavibar1Layout.setVerticalGroup(
            jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar1Layout.createSequentialGroup()
                .addGroup(jxpanFindNavibar1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxSearchFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 4, Short.MAX_VALUE))
        );

        jXPanel2.add(jxpanFindNavibar1, java.awt.BorderLayout.NORTH);

        jxpanCenter.add(jXPanel2);

        jxBtnAddTo.setText(">>");
        jxBtnAddTo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnAddToActionPerformed(evt);
            }
        });

        jxBtnRemove.setText("<<");
        jxBtnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnRemoveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel5Layout = new javax.swing.GroupLayout(jXPanel5);
        jXPanel5.setLayout(jXPanel5Layout);
        jXPanel5Layout.setHorizontalGroup(
            jXPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jxBtnAddTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jxBtnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jXPanel5Layout.setVerticalGroup(
            jXPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel5Layout.createSequentialGroup()
                .addGap(110, 110, 110)
                .addComponent(jxBtnAddTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jxBtnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(178, Short.MAX_VALUE))
        );

        jxpanCenter.add(jXPanel5);

        jXPanel1.setLayout(new java.awt.BorderLayout(0, 1));

        jxTbListSubjectRegistration.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã môn học", "Tên tên môn học", "Loại môn học", "Số tín chỉ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jxTbListSubjectRegistration.setGridColor(new java.awt.Color(153, 153, 153));
        jxTbListSubjectRegistration.setSelectionBackground(new java.awt.Color(204, 204, 204));
        jxTbListSubjectRegistration.setSortsOnUpdates(false);
        jxTbListSubjectRegistration.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jxTbListSubjectRegistrationMousePressed(evt);
            }
        });
        jScrollPane.setViewportView(jxTbListSubjectRegistration);

        jXPanel1.add(jScrollPane, java.awt.BorderLayout.CENTER);

        jxpanFindNavibar2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar2.setPreferredSize(new java.awt.Dimension(914, 30));

        jXLabel6.setText("Tìm kiếm sinh viên:");

        jXLabel7.setText("Danh sách môn học sinh viên đăng ký");
        jXLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout jxpanFindNavibar2Layout = new javax.swing.GroupLayout(jxpanFindNavibar2);
        jxpanFindNavibar2.setLayout(jxpanFindNavibar2Layout);
        jxpanFindNavibar2Layout.setHorizontalGroup(
            jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jxSearchFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jxpanFindNavibar2Layout.setVerticalGroup(
            jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibar2Layout.createSequentialGroup()
                .addGroup(jxpanFindNavibar2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxSearchFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 4, Short.MAX_VALUE))
        );

        jXPanel1.add(jxpanFindNavibar2, java.awt.BorderLayout.NORTH);

        jxpanCenter.add(jXPanel1);

        jpanContent.add(jxpanCenter, java.awt.BorderLayout.CENTER);

        jpanTableDetails.add(jpanContent, java.awt.BorderLayout.CENTER);

        jxpanDetails.add(jpanTableDetails, java.awt.BorderLayout.CENTER);

        add(jxpanDetails, java.awt.BorderLayout.CENTER);

        jxpanHeader.setLayout(new java.awt.BorderLayout());

        jxpanTitleHeader.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jXLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jXLabel5.setText("ĐĂNG KÝ MÔN HỌC");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jxpanTitleHeader.add(jXLabel5);

        jxpanHeader.add(jxpanTitleHeader, java.awt.BorderLayout.PAGE_START);

        jxpanInfoHeader.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanInfoHeader.setLayout(new java.awt.BorderLayout());

        jxpanInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "THÔNG TIN", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        jxLabNameOfFaculty.setText("Học kỳ ");

        jxCbSemester.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbSemesterItemStateChanged(evt);
            }
        });

        jxLabNameOfFaculty2.setText("Năm học");

        jxCbYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxCbYearActionPerformed(evt);
            }
        });

        jXLabel1.setText("Mã số sinh viên");

        jxTxtStudentId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jxTxtStudentIdKeyPressed(evt);
            }
        });

        jXLabel2.setText("Họ & tên");

        jXLabel8.setText("Ngành học");

        jXLabel9.setText("Ngày đăng ký");

        jxDpDateRegistration.setFormats("dd/MM/yyyy");

        jxBtnOtherStudent.setText("Sinh viên khác");
        jxBtnOtherStudent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnOtherStudentActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jxpanInfoLayout = new javax.swing.GroupLayout(jxpanInfo);
        jxpanInfo.setLayout(jxpanInfoLayout);
        jxpanInfoLayout.setHorizontalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanInfoLayout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jxTxtNameOfStudent, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jxTxtStudentId, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxBtnOtherStudent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jxDpDateRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(jxTxtNameOfMajor, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(60, 60, 60)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(246, Short.MAX_VALUE))
        );
        jxpanInfoLayout.setVerticalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jxTxtStudentId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jxBtnOtherStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxTxtNameOfStudent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxDpDateRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jxTxtNameOfMajor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 0, 0))
        );

        jxpanInfoHeader.add(jxpanInfo, java.awt.BorderLayout.CENTER);

        jxpanHeader.add(jxpanInfoHeader, java.awt.BorderLayout.CENTER);

        add(jxpanHeader, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jxBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnCancelActionPerformed
        
        if(this.jxTbListSubjectRegistration.m_isAdd){
            jxTbListSubjectRegistration.m_isAdd = false;
            refreshDataControls();
        }
        else
            if(this.jxTbListSubjectRegistration.m_isUpdate){
                this.jxTbListSubjectRegistration.m_isUpdate = false;
                jxBtnAddTo.setEnabled(false);
                jxBtnRemove.setEnabled(false);
                jxBtnSave.setEnabled(false);
                jxBtnCancel.setEnabled(false);
                
                jxBtnUpdate.setEnabled(true);
                jxBtnShowRegistration.setEnabled(true);
                
                arrSubjectRegistration.clear();
                arrSubjectRegistration = arrSubjectRegistrationActionUpdate;
                initJXTableSubjectRegistration(arrSubjectRegistration);
                calculatorInfoRegistration();
            }
    }//GEN-LAST:event_jxBtnCancelActionPerformed

    private void jxCbSemesterItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbSemesterItemStateChanged
//        if(jxCbSemester.getSelectedItem() != null)
//        {
//            SemesterDTO obj = (SemesterDTO) evt.getItem();
//            if (obj.equals(objAddNewSemester)) {
//                JOptionPane.showMessageDialog(null, "Thêm mới HOC KY!");
//                jxCbSemester.setSelectedItem(null);
//            } else {
//                if (this.jxTbListSubjectRegistration.m_isAdd || this.jxTbListSubjectRegistration.m_isUpdate) {
//                    jxTbListSubjectRegistration.getModel().setValueAt(obj, currentRow, 1);
//                }
//            }
//        }
    }//GEN-LAST:event_jxCbSemesterItemStateChanged

    private void jxBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnSaveActionPerformed
        save();
    }//GEN-LAST:event_jxBtnSaveActionPerformed

    private void jxBtnShowRegistrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnShowRegistrationActionPerformed

    }//GEN-LAST:event_jxBtnShowRegistrationActionPerformed

    private void jxTxtStudentIdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jxTxtStudentIdKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER)
        {
            initObjectStudentRegistration(jxTxtStudentId.getText().trim());
        }
    }//GEN-LAST:event_jxTxtStudentIdKeyPressed

    private void jxCbYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxCbYearActionPerformed
//        if(jxCbYear.getSelectedItem() != null)
//        {
//            AcademicYearDTO obj = (AcademicYearDTO) evt.getItem();
//            if (obj.equals(objAddNewYear)) {
//                JOptionPane.showMessageDialog(null, "Thêm mới NAM HOC!");
//                jxCbYear.setSelectedItem(null);
//            } else {
//                if (this.jxTbListSubjectRegistration.m_isAdd || this.jxTbListSubjectRegistration.m_isUpdate) {
//                    jxTbListSubjectRegistration.getModel().setValueAt(obj, currentRow, 2);
//                }
//            }
//        }
    }//GEN-LAST:event_jxCbYearActionPerformed

    private void jxBtnOtherStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnOtherStudentActionPerformed
       
        this.jxTbListSubjectRegistration.m_isAdd = false;
        this.jxTbListSubjectRegistration.m_isUpdate = false;
//        refreshDataControls();
        jxBtnAddTo.setEnabled(false);
        jxBtnRemove.setEnabled(false);
        jxBtnUpdate.setEnabled(false);
        jxBtnShowRegistration.setEnabled(false);
    }//GEN-LAST:event_jxBtnOtherStudentActionPerformed

    private void jxBtnAddToActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnAddToActionPerformed
         if(jxTbListSubjectWillOpen.getRowCount()>0&&jxCbSemester.getSelectedItem()!= null && jxCbYear.getSelectedItem()!= null)
        {
            int[] row = jxTbListSubjectWillOpen.getSelectedRows();
            for(int i : row){
                SubjectDisplay objSub = new SubjectDisplay(jxTbListSubjectWillOpen.getValueAt(i, 0).toString(), 
                        jxTbListSubjectWillOpen.getValueAt(i, 1).toString(),
                        jxTbListSubjectWillOpen.getValueAt(i, 2).toString(),
                        Integer.valueOf(jxTbListSubjectWillOpen.getValueAt(i, 3).toString()));
                if(jxTbListSubjectRegistration.m_isAdd||jxTbListSubjectRegistration.m_isUpdate){
                    //Kiem tra mon tien quyet
                    if(checkSubjectPrerequisiteIsValid(objSub)){
                        if(!arrSubjectRegistration.contains(objSub))
                            arrSubjectRegistration.add(objSub);
                        initJXTableSubjectRegistration(arrSubjectRegistration);
                        //tinh toan du lieu
                        calculatorInfoRegistration();
                }
            }
//            else
//                if(jxTbListSubjectRegistration.m_isUpdate)
//                {
//                    if(!listSubjectOpenToUpdate.contains(objSub))
//                        listSubjectOpenToUpdate.add(objSub);
//                    initJTableForSubjectOpen(arrSubjectRegistration);
//                }
            }
        }
    }//GEN-LAST:event_jxBtnAddToActionPerformed

    private void jxBtnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnRemoveActionPerformed
        
        if(jxTbListSubjectRegistration.getRowCount()>0&&jxCbSemester.getSelectedItem()!= null&&jxCbYear.getSelectedItem()!= null)
        {
            int[] row = jxTbListSubjectRegistration.getSelectedRows();
            for(int i = row.length - 1; i>=0; i--){
            SubjectDisplay objSub = new SubjectDisplay(jxTbListSubjectRegistration.getValueAt(row[i], 0).toString(), 
                    jxTbListSubjectRegistration.getValueAt(row[i], 1).toString(),
                    jxTbListSubjectRegistration.getValueAt(row[i], 2).toString(),
                    Integer.valueOf(jxTbListSubjectRegistration.getValueAt(row[i], 3).toString()));
            if(jxTbListSubjectRegistration.m_isAdd||jxTbListSubjectRegistration.m_isUpdate){
                if(arrSubjectRegistration.contains(objSub))
                    arrSubjectRegistration.remove(objSub);
                initJXTableSubjectRegistration(arrSubjectRegistration);
                //tinh toan du lieu
                calculatorInfoRegistration();
            }
//            else
//                if(jxTbListSubjectRegistration.m_isUpdate)
//                {
//                    if(listSubjectOpenToUpdate.contains(objSub))
//                        listSubjectOpenToUpdate.remove(objSub);
//                    initJTableForSubjectOpen(listSubjectOpenToUpdate);
//                }
            }
        }       
    }//GEN-LAST:event_jxBtnRemoveActionPerformed

    private void jxTbListSubjectWillOpenMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxTbListSubjectWillOpenMousePressed
      //Thiet lap cho 2 JXButton AddTo va Remove
        if(jxTbListSubjectWillOpen.getSelectedRow()>0&&
                jxTbListSubjectRegistration.m_isAdd||
                jxTbListSubjectRegistration.m_isUpdate)
        {
            jxBtnRemove.setEnabled(false);
            jxBtnAddTo.setEnabled(true);
        }
    }//GEN-LAST:event_jxTbListSubjectWillOpenMousePressed

    private void jxTbListSubjectRegistrationMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxTbListSubjectRegistrationMousePressed
       //Thiet lap cho 2 JXButton AddTo va Remove
        if(jxTbListSubjectRegistration.getSelectedRow()>0 && 
                jxTbListSubjectRegistration.m_isAdd || 
                jxTbListSubjectRegistration.m_isUpdate)
        {
            jxBtnRemove.setEnabled(true);
            jxBtnAddTo.setEnabled(false);
        }
    }//GEN-LAST:event_jxTbListSubjectRegistrationMousePressed

    private void jxBtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnUpdateActionPerformed

        jxTbListSubjectRegistration.m_isUpdate = true;
        jxBtnSave.setEnabled(true);
        jxBtnCancel.setEnabled(true);
        jxBtnAddTo.setEnabled(true);
        jxBtnUpdate.setEnabled(false);
        jxBtnShowRegistration.setEnabled(false);
        
        //Copy tu arrSubjectRegistration sang arrSubjectRegistrationActionUpdate
        arrSubjectRegistrationActionUpdate = new ArrayList<>();
        for(SubjectDisplay obj :  arrSubjectRegistration)
        {
            arrSubjectRegistrationActionUpdate.add(obj);
        }
    }//GEN-LAST:event_jxBtnUpdateActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
       jxTxtStudentId.requestFocus();
    }//GEN-LAST:event_formComponentShown


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel10;
    private org.jdesktop.swingx.JXLabel jXLabel11;
    private org.jdesktop.swingx.JXLabel jXLabel12;
    private org.jdesktop.swingx.JXLabel jXLabel13;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel4;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel7;
    private org.jdesktop.swingx.JXLabel jXLabel8;
    private org.jdesktop.swingx.JXLabel jXLabel9;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel3;
    private org.jdesktop.swingx.JXPanel jXPanel4;
    private org.jdesktop.swingx.JXPanel jXPanel5;
    private javax.swing.JPanel jpanContent;
    private javax.swing.JPanel jpanFuntionalDetails;
    private javax.swing.JPanel jpanTableDetails;
    private org.jdesktop.swingx.JXButton jxBtnAddTo;
    private org.jdesktop.swingx.JXButton jxBtnCancel;
    private org.jdesktop.swingx.JXButton jxBtnOtherStudent;
    private org.jdesktop.swingx.JXButton jxBtnRemove;
    private org.jdesktop.swingx.JXButton jxBtnSave;
    private org.jdesktop.swingx.JXButton jxBtnShowRegistration;
    private org.jdesktop.swingx.JXButton jxBtnUpdate;
    private org.jdesktop.swingx.JXComboBox jxCbSemester;
    private org.jdesktop.swingx.JXComboBox jxCbYear;
    private org.jdesktop.swingx.JXDatePicker jxDpDateRegistration;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty2;
    private org.jdesktop.swingx.JXLabel jxLblCountCreditPractice;
    private org.jdesktop.swingx.JXLabel jxLblCountCreditTheory;
    private org.jdesktop.swingx.JXLabel jxLblTotalCredit;
    private org.jdesktop.swingx.JXLabel jxLblTotalMoneyFee;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty2;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty4;
    private mnstudent.global.MyTable jxTbListSubjectRegistration;
    private mnstudent.global.MyTable jxTbListSubjectWillOpen;
    private org.jdesktop.swingx.JXTextField jxTxtNameOfMajor;
    private org.jdesktop.swingx.JXTextField jxTxtNameOfStudent;
    private org.jdesktop.swingx.JXTextField jxTxtStudentId;
    private org.jdesktop.swingx.JXPanel jxpanCenter;
    private org.jdesktop.swingx.JXPanel jxpanDetails;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar1;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar2;
    private org.jdesktop.swingx.JXPanel jxpanHeader;
    private org.jdesktop.swingx.JXPanel jxpanInfo;
    private org.jdesktop.swingx.JXPanel jxpanInfoHeader;
    private org.jdesktop.swingx.JXPanel jxpanTitleHeader;
    // End of variables declaration//GEN-END:variables
}